package org.example.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
public class ConsumerController {
    @Value("${server.port}")
    private String port;
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping(value = "/do-get")
    public String doGet() throws InterruptedException {
        String url = "http://producer/do-get?name=commander";
        ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);

        return response.getBody();
    }

    @PostMapping(value = "/do-post")
    public String doPost(@RequestBody Map<String, Object> body) throws InterruptedException {
        String url = "http://producer/do-post";
        ResponseEntity<String> response = restTemplate.postForEntity(url, body, String.class);

        return response.getBody();
    }
}
